import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
const isAdmin=(localStorage.getItem('role')=='admin')
/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */

const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true,
  },
  {
    path: '/tabList',
    component: () => import('@/views/userLogin/tabList'),
    hidden: true,
  },
  {
    path: '/userAddContent',
    name:'userAddContent',
    component: () => import('@/views/userLogin/components/userAddContent'),
    hidden: true,
  },
  {
    path: '/',
    component: Layout,
    redirect: '/homePage',
    children: [{
      path: 'homePage',
      name: 'homePage',
      component: () => import('@/views/homePage/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/admin',
    component: Layout,
    redirect: '/admin/tableDev',
    name: '账号管理',
    meta: { title: '账号管理', icon: 'example' },
    children: [
      {
        path: 'tableDev',
        name: 'TableDev',
        component: () => import('@/views/admin/table'),
        meta: { title: '账号列表', icon: 'table', admin: true }
      },
      {
        path: 'addDev',
        name: 'addDev',
        hidden: true,
        component: () => import('@/views/admin/add'),
        meta: { title: '添加(编辑)账号', icon: 'table', all: true }
      },
      {
        path: 'detail',
        name: 'detail',
        hidden: true,
        component: () => import('@/views/admin/detail'),
        meta: { title: '查看账号', icon: 'table', admin: true }
      },
      {
        path: 'addTag',
        name: 'addTag',
        hidden: true,
        component: () => import('@/views/tags/addTag'),
        meta: { title: '添加标签', icon: 'table', all: true }
      },
      {
        path: 'tagDetail',
        name: 'tagDetail',
        hidden: true,
        component: () => import('@/views/tags/tagDetail'),
        meta: { title: '标签详情', icon: 'table', all: true }
      },
      {
        path: 'addContent',
        name: 'addContent',
        hidden: true,
        component: () => import('@/views/content/addContent'),
        meta: { title: '添加内容', icon: 'table', all: true }
      },
      {
        path: 'contentDetail',
        name: 'contentDetail',
        hidden: true,
        component: () => import('@/views/content/contentDetail'),
        meta: { title: '查看内容', icon: 'table', all: true }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/tableUser',
    name: '用户',
    meta: { title: '用户', icon: 'example' },
    children: [
      {
        path: 'tableUser',
        name: 'tableUser',
        component: () => import('@/views/user/tableUser'),
        meta: { title: '用户列表', icon: 'table', admin: true }
      }
    ]
  },
  {
    path: '/info',
    component: Layout,
    redirect: '/info/information',
    name: '基本信息',
    meta: { title: '基本信息', icon: 'example' },
    children: [
      {
        path: 'information',
        name: 'information',
        component: () => import('@/views/admin/information'),
        meta: { title: '基本信息', icon: 'table' }
      }
    ]
  },
  {
    path: '/ele',
    component: Layout,
    redirect: '/ele/eleList',
    name: '详情',
    meta: { title: '详情', icon: 'example' },
    children: [
      {
        path: 'eleList',
        name: 'eleList',
        component: () => import('@/views/manageTeam/eleList'),
        meta: { title: '标签管理', icon: 'table' }
      }
    ]
  },
  {
    path: '/content',
    component: Layout,
    redirect: '/content/manageContent',
    name: '详情',
    meta: { title: '详情', icon: 'example' },
    children: [
      {
        path: 'manageContent',
        name: 'manageContent',
        component: () => import('@/views/manageTeam/manageContent'),
        meta: { title: '内容管理', icon: 'table' }
      }
    ]
  },
  {
    path: '/intro',
    component: Layout,
    redirect: '/intro/teamInfo',
    name: '详情',
    meta: { title: '详情', icon: 'example' },
    children: [
      {
        path: 'teamInfo',
        name: 'teamInfo',
        component: () => import('@/views/company/teamInfo'),
        meta: { title: '公司介绍', icon: 'table'}
      }
    ]
  },
  {
    path: '/pro',
    component: Layout,
    redirect: '/pro/teamProduct',
    name: '详情',
    meta: { title: '详情', icon: 'example' },
    children: [
      {
        path: 'teamProduct',
        name: 'teamProduct',
        component: () => import('@/views/company/teamProduct'),
        meta: { title: '产品介绍', icon: 'table' }
      }
    ]
  },
  {
    path: '/rule',
    component: Layout,
    redirect: '/rule/teamRule',
    name: '详情',
    meta: { title: '详情', icon: 'example' },
    children: [
      {
        path: 'teamRule',
        name: 'teamRule',
        component: () => import('@/views/company/teamRule'),
        meta: { title: '晋升及制度', icon: 'table' }
      }
    ]
  },
  {
    path: '/suggestion',
    component: Layout,
    redirect: '/suggestion/advice',
    name: '详情',
    meta: { title: '详情', icon: 'example' },
    children: [
      {
        path: 'advice',
        name: 'advice',
        component: () => import('@/views/suggestion/advice'),
        meta: { title: '意见反馈', icon: 'table', admin: true}
      }
    ]
  },
  // {
  //   path: '/userLogin',
  //   component: Layout,
  //   redirect: '/userLogin/tabList',
  //   name: '详情',
  //   meta: { title: '详情', icon: 'example' },
  //   children: [
  //     {
  //       path: 'tabList',
  //       name: 'tabList',
  //       component: () => import('@/views/userLogin/tabList'),
  //       meta: { title: '测试', icon: 'table', admin: true}
  //     }
  //   ]
  // },
  { path: '*', redirect: '/404', hidden: true }
]
function createRouter() {
  return new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({
      y: 0
    }),
    routes: constantRoutes,
    routesTemp: constantRoutes,
  })
}
const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
export default router
